<template>
	<view>
            <u-skeleton :loading="isFirst" rows="10">
				<view class="">
			<view class="">
				<u-tabs :list="list" :itemStyle="{ width: '42%',marginBottom:'20rpx',marginTop:'20rpx'}"
					:current="current" active-color="#30B1B7" lineColor="red" lineWidth="40"
					@change="tagChange"></u-tabs>
				<view class="" v-if="current == 0 && isOverBrush">
					   <view class="options" v-for="(item,index) in isOverBrush" :key="index"
					   	@click.stop="selectResult(item)">
					   	<view class="o_top option">
					   		<view class="floatleft mlw" style="font-size: 36rpx;font-weight: bold;">
					   			{{item.time}}
					   		</view>
					   
					   		<view class="floatright y_tag  y_tag_bgSuccess mrw"
					   			v-if="item.isTimeout==null">已完成</view>
					   
					   		<!-- <view class="floatright y_tag  y_tag_bgDanger mrw"
					   			v-if="item.startCountDown!=0 && item.isFinish==0">未开始
					   
					   		</view> -->
					   
					   	</view>
					   
					   	<view class="o_top option">
					   		<view class="floatleft  mlw">
					   			<view class="y_tag floatleft ">
					   				{{item.count}}道题
					   			</view>
					   
					   			<view class="y_tag floatleft mlw">
					   				{{item.rightPercent}}%正确率
					   			</view>
					   
					   			<view class="y_tag floatleft mlw">
					   				答题时长:{{item.timeCount==null?'-':item.timeCount}}秒
					   			</view>
					   
					   		</view>
					   
					   	</view>
					   
					   
					   
					   
					   	<view class="o_top option examtime">
					   		
					   		<view class="" v-if="item.questionBanks.length==0">
					   		题库：无
					   		</view>
					   		<view class="" v-if="item.questionBanks.length!=0">
					   			<view class="" style="float: left;margin-top: 8rpx;">
					   				题库：
					   			</view>
					   			<view class="questions" v-for="(qitem,i) in item.questionBanks" :key="i" style="">
					   				<view class="y_tag floatleft y_tag_bgPrimary">
					   					{{qitem}}
					   				</view>
					   			</view>
					   		</view>
					   		<view class="y_tag floatleft y_tag_bgPrimary"
					   			style="margin-right: 20rpx; margin: 10px;">
					   			查看详情
					   		</view>
					   	</view>
					   
					   </view>

					   
				</view>
				<view class="" v-if="current == 1 && notOverBush">
					   <view class="options" v-for="(item,index) in notOverBush" :key="index"
					   	@click.stop="continue_brush(item)">
					   	<view class="o_top option">
					   		<view class="floatleft mlw" style="font-size: 36rpx;font-weight: bold;">
					   			{{item.time}}
					   		</view>
					   
					   		<view class="floatright y_tag  y_tag_bgWarning mrw"
					   			v-if="item.isTimeout==0">未完成</view>
					   <view class="iconfont icon-yiguoqi" style="font-size: 60rpx; color: red; margin-right: 10rpx;"
					   	v-if="item.isTimeout==1"></view>
					   		<!-- <view class="floatright y_tag  y_tag_bgDanger mrw"
					   			v-if="item.startCountDown!=0 && item.isFinish==0">未开始
					   
					   		</view> -->
					   
					   	</view>
					   
					   	<view class="o_top option">
					   		<view class="floatleft  mlw">
					   			<view class="y_tag floatleft ">
					   				{{item.count}}道题
					   			</view>
					   
					   
					   		</view>
					   
					   	</view>
					   
					   
					   
					   
					   	<view class="o_top option examtime">
					   		
					   		<view class="" v-if="item.questionBanks.length==0">
					   		题库：无
					   		</view>
					   		<view class="" v-if="item.questionBanks.length!=0">
					   			<view class="" style="float: left;margin-top: 8rpx;">
					   				题库：
					   			</view>
					   			<view class="questions" v-for="(qitem,i) in item.questionBanks" :key="i" style="">
					   				<view class="y_tag floatleft y_tag_bgPrimary">
					   					{{qitem}}
					   				</view>
					   			</view>
					   		</view>
					   		<view class="y_tag floatleft y_tag_bgPrimary"
					   			style="margin-right: 20rpx; margin: 10px;" 	v-if="item.isTimeout==0">
					   			继续答题
					   		</view>
					   	</view>
					   
					   
					   </view>

				</view>
			</view>

			
			
				
			</view>
			
			</u-skeleton>
	</view>
</template>

<script>
	import {
		GetUserRepeatHistory
	} from '../../../api/brush_questions.js';
	export default {
		data() {
			return {
				pages:{
					page:1,
					limit:10,
					total:0
				},
				pages_yes:{
					page:1,
					limit:10,
					total:0
				},
				pages_no:{
					page:1,
					limit:10,
					total:0
				},
				isFirst:true,
				current:0,
				isOverBrush:[],
				notOverBush:[],
				list: [{
						name: '已完成'
					},
					{
						name: '未完成'
					},
				],
				
			}
		},
		 onReachBottom() {
			if(this.current==0){
				uni.showLoading({
					title:"加载中"
				})
				// console.log(!rguspages_no.pages.total,pages_no.pages.page*pages_no.pages.limit);
				console.log(this.pages_yes.total,this.pages_yes.page*this.pages_yes.limit,"GGFGFFHBFN");
				if(this.pages_yes.total>this.pages_yes.page*this.pages_yes.limit){
						this.pages_yes.limit+=10;
				}else{
					
					this.pages_yes.limit=this.pages_yes.total;
					setTimeout(()=>{
						uni.hideLoading();
						uni.showToast({
							title:"到底啦",
							icon:"none"
						})
					}, 1000);
					return
				
				}
					
				GetUserRepeatHistory({page:this.pages_yes.page,limit:this.pages_yes.limit,isFinish:1}).then(res=>{
					if(res.result==0){
						this.isOverBrush=res.data.data;
							uni.hideLoading();
					}
				})
			}
			if(this.current==1){
				uni.showLoading({
					title:"加载中"
				})
				// console.log(!rguspages_no.pages.total,pages_no.pages.page*pages_no.pages.limit);
				console.log(this.pages_no.total,this.pages_no.page*this.pages_no.limit,"GGFGFFHBFN");
				if(this.pages_no.total>this.pages_no.page*this.pages_no.limit){
						this.pages_no.limit+=10;
						
				}else{
					
					this.pages_no.limit=this.pages_no.total;
					setTimeout(()=>{
						uni.hideLoading();
						uni.showToast({
							title:"到底啦",
							icon:"none"
						})
					}, 1000);
					return
				
				}
	
				GetUserRepeatHistory({page:this.pages_no.page,limit:this.pages_no.limit,isFinish:0}).then(res=>{
					if(res.result==0){
						this.notOverBush=res.data.data;
							uni.hideLoading();
					}
				})
				
			}
			
			
		},
		onShow() {
			// this.getUserRepeatHistory();
			Promise.allSettled([
				GetUserRepeatHistory({page:1,limit:10,isFinish:1}),
				GetUserRepeatHistory({page:1,limit:10,isFinish:0})
				]).then(res=>{
					console.log(res,"ndsjsdfksd");
					const result=res.find(d=>res.status=="rejected");
					if(result){
						uni.showToast({
							title:"数据异常,有问题请联系管理员"
						})
					}
					this.pages_yes.total=res[0].value.data.total;
					this.isOverBrush=res[0].value.data.data;
					
					this.pages_no.total=res[1].value.data.total;
					this.notOverBush=res[1].value.data.data;
					this.isFirst=false;
				})
		},
		
		methods: {
			selectResult(item){
				uni.redirectTo({
					url:"/pages/brush_questions/result/result?id="+item.id
				})
			},
			/**
			 * 点击未完成继续刷题
			 */
			continue_brush(item){
				if(item.isTimeout==1){
					uni.showToast({
						icon:"none",
						title:"已过期"
					})
				}else{
					uni.navigateTo({
						url:"/pages/brush_questions/brush_history/continue_brush/continue_brush?code="+item.id
					})
				}
				
			  
			},
			/**标签页改变事件
			 * @param {Object} index
			 */
			tagChange(index) {
				this.current = index.index;
				//如报错则用this.current = index代替上行
			},
			/**
			 * 获取已完成的刷题数据
			 */
			getUserRepeatHistory(){
				GetUserRepeatHistory({page:1,limit:10,isFinish:1}).then(res=>{
					if(res.result===0){
						this.total=res.data.total;
						this.isOverBrush=res.data.data;
					}
				})
			}
		}
	}
</script>

<style>
	.questions{
		float: left;
	}
	.questions:not(:first-child){
		margin-left: 6rpx;
	}
	.examtime {
		font-size: 12px;
		color: rgb(128, 128, 128);
		margin-left: 10rpx;
	}

	.option {
		margin-top: 10rpx;
		display: flex;
		justify-content: space-between;
		width: 100%;
	}

	.options {
		margin-left: 1.2%;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		margin-top: 10rpx;
		// display: flex;
		// justify-content: space-between;
		width: 97%;
		border-radius: 10rpx;
		border: 1px solid rgba(25, 137, 250, 0.2);
	}

	.options:last-child {
		margin-bottom: 10rpx;
	}
	.examtime {
		font-size: 12px;
		color: rgb(128, 128, 128);
		margin-left: 10rpx;
	}

	.option {
		margin-top: 10rpx;
		display: flex;
		justify-content: space-between;
		width: 100%;
	}

	.options {
		margin-left: 1.2%;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		margin-top: 10rpx;
		// display: flex;
		// justify-content: space-between;
		width: 97%;
		border-radius: 10rpx;
		border: 1px solid rgba(25, 137, 250, 0.2);
	}

	.options:last-child {
		margin-bottom: 10rpx;
	}

</style>
